package com.language.points.proxy;

/**
 * 代理示例 - 测试
 * @author yll
 * @version 1.0.0
 * @date 2024/04/25 15：20
 * */
public class ProxyTest {


    public static void main(String[] args) {
        DemoService demoService = new DemoServiceImpl();
        System.out.println("JDK代理演示 start...");
        JdkProxyHandler jdkProxyHandler = new JdkProxyHandlerImpl(demoService);
        DemoService jdkProxyDemoService = (DemoService) jdkProxyHandler.getProxObj();
        jdkProxyDemoService.start();
        jdkProxyDemoService.run();
        jdkProxyDemoService.stop();
        System.out.println("JDK代理演示 stop!");
        System.out.println("****************************************************");
        System.out.println("静态代理演示 start...");
        CglibProxy cglibProxy = new CglibProxyImpl(demoService);
        DemoService cglibProxyDemoService = (DemoService)cglibProxy.getProxObj();
        cglibProxyDemoService.start();
        cglibProxyDemoService.run();
        cglibProxyDemoService.stop();
        System.out.println("静态代理演示 stop!");
    }


    public static int move(int count, int num, String source, String target, String temp){
        //move(1, 4, "A", "C", "B");
        if( num < 1){
            return count;
        }
        if( num == 1){
            System.out.println("第 " + (count++) + " 步：从 " + source + " -> " + target + " ;");
            return count;
        }
        //
        count = move(count, num - 1, source, temp, target);
        count = move(count, 1, source, target, temp);
        count = move(count, num - 1, temp, target, source);
        return count;
    }
}
